package com.imay.live.adapter;


import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.live.activity.dynamics.SearchActivity;
import com.imay.live.model.SearchHistoryModel;
import com.imay.live.R;

import java.util.List;

/**
 * Created by liangzhenxiong on 2017/4/6 0006.
 * 搜索历史
 */

public class SearchHistoryAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {


    public final static int VIEWTYPE_LINEAR_TITLE = 2;//标题
    public final static int VIEWTYPE_LINEAR_CONTENT = 0x118;//推荐结果


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public SearchHistoryAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(VIEWTYPE_LINEAR_CONTENT, R.layout.searchhis_item);
        addItemType(VIEWTYPE_LINEAR_TITLE, R.layout.searchhis_title_item);

    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {

        if (item.getItemType() == VIEWTYPE_LINEAR_TITLE) {
            int postion = helper.getAdapterPosition() - getHeaderLayoutCount();
            if (postion > 0) {
                helper.setVisible(R.id.bg_top_view, true);
            } else {
                helper.setVisible(R.id.bg_top_view, false);
            }
            SearchActivity.SearchTitleView searchTitleView = (SearchActivity.SearchTitleView) item;
            helper.setText(R.id.tv_title, searchTitleView.getTitle());
        } else if (item.getItemType() == VIEWTYPE_LINEAR_CONTENT) {
            helper.addOnClickListener(R.id.tv_h_content);
            SearchHistoryModel searchHistoryModel = (SearchHistoryModel) item;
            if (searchHistoryModel.getSpanstring() == null) {
                helper.setText(R.id.tv_h_content, searchHistoryModel.getString());
            } else {
                helper.setText(R.id.tv_h_content, searchHistoryModel.getSpanstring());
            }

        }
    }
}
